<template>
  <el-dialog title="新增岗位" v-model="dialogVisible" width="50%">
    <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
      <el-form-item label="岗位名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入岗位名称"></el-input>
      </el-form-item>
      <el-form-item label="岗位描述" prop="description">
        <el-input v-model="form.description" placeholder="请输入岗位描述" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button type="primary" @click="submitForm">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import {addPosition} from "@/api/system.js";

export default {
  name: "position-dialog",
  data() {
    return {
      dialogVisible: false,
      form: {
        name: '',
        description: ''
      },
      rules: {
        name: [{ required: true, message: '请输入岗位名称', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.formRef.validate().then(() => {
        addPosition(this.form).then(() => {
          this.dialogVisible = false
          this.$message.success('新增岗位成功')
          this.$refs.formRef.resetFields()
          this.$refs.formRef.clearValidate()
          this.$emit('refreshList')
        })
      })
    },
    closeDialog() {
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped>

</style>
